package com.view.purchasemanage;

import com.bean.Goods;
import com.bean.Purchase;
import com.bean.Role;
import com.lovo.netCRM.component.LovoButton;
import com.lovo.netCRM.component.LovoComboBox;
import com.lovo.netCRM.component.LovoTxt;
import com.service.PowerService;
import com.service.PurchaseService;
import com.service.RoleService;
import com.service.UserService;
import com.service.impl.PowerServiceImpl;
import com.service.impl.PurchaseServiceImpl;
import com.service.impl.RoleServiceImpl;
import com.service.impl.UserServiceImpl;
import com.util.MyCheckBox;
import com.view.MainFrame;
import com.view.jurisdictionmanage.RoleAddDialog;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
import java.util.List;

public class GoodsUpdateDialog extends JDialog {

    private LovoButton addBtn;
    private LovoButton cancelBtn;
    private LovoTxt numberTxt;


    private MainFrame frame ;
    private PurchaseService purchaseService = new PurchaseServiceImpl();

    private Purchase purchase;
    private int key;

    public GoodsUpdateDialog(MainFrame frame,int key) {
        // TODO Auto-generated constructor stub
        super(frame,"修改商品数量",true);
        this.frame = frame;
        this.key = key;
        this.purchase = frame.getpIMP().getPurchase();
        this.setBounds(350, 250, 400, 400);
        this.setLayout(null);
        this.init();
        this.setVisible(true);
    }


    private void init() {
        // TODO Auto-generated method stub

        numberTxt = new LovoTxt("数量",150,260,this);


        this.addBtn = new LovoButton("修改", 100, 320, this);
        this.cancelBtn = new LovoButton("取消", 250, 320, this);

        addBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int numberTxtText = Integer.parseInt(numberTxt.getText());

                if(purchaseService.updateGoodsNumber(key,numberTxtText)){
                    JOptionPane.showMessageDialog(null,"修改成功");
                    frame.flush();
                    GoodsUpdateDialog.this.dispose();
                }else{
                    JOptionPane.showMessageDialog(null,"添加失败");
                }
            }
        });

    }

}
